myApp.controller("registerCtrl", function($scope, $state, $http){
	var user = {};
	$scope.registerClick = function(){
		console.log($scope.user);
		user = $scope.user;
		$http({
			method: "post",
			url: "/register",
			params: {
				user: user
			}
		}).success(function(data){
			console.log("success---->"+data);
			if(data == 'has'){
				alert("邮箱已经注册过了！")
			}else if(data == 'success'){
				alert("注册成功！")
				$state.go('/login');
			}else{
				alert("未知错误！")
			}
		}).error(function(data){
			console.log("error------>"+data);
		});
	}
});

myApp.directive('pwCheck', [function () {
			return {
				require : 'ngModel',
				link : function (scope, elem, attrs, ctrl) {
					var firstPassword = '#' + attrs.pwCheck;
					$(elem).add(firstPassword).on('keyup', function () {
						scope.$apply(function () {
							var v = elem.val() === $(firstPassword).val();
							ctrl.$setValidity('pwmatch', v);
						});
					});
				}
			}
		}
	]);



